library(manysvms)
library(SupportVectorLab)
source("bls_bsh_tsvm.R")
source("cL2p_ls_tsvm.R")
source("closs_tbsvm.R")
source("Test-Classification-Example.R")
source("Test-Classification-Example-Noisy.R")
kernel_type <- "linear"
path <- "../results-linear-classification/"


num_dataset <- 13
seed_cv            <- 4651
seed_label_noise   <- 544
set.seed(seed_cv)
seed_cv_vec          <- sample(10000, num_dataset)
set.seed(seed_label_noise)
seed_label_noise_vec <- sample(10000, num_dataset)
start_time <- Sys.time()
# ----------------------------------------------------------------------- raisin
load("../data-classification/raisin.Rda")
X <- raisin[, 1:7]
y <- as.character(as.matrix(raisin[, 8]))

classification_example(X, y, seed = seed_cv_vec[1], kernel_type = kernel_type,
                       path = path, file_name = "0_raisin")
classification_example_noisy(X, y, seed = seed_cv_vec[1], seed_noisy = seed_label_noise_vec[1], p = 0.25,
                             kernel_type = kernel_type,
                             path = path, file_name = "25_raisin")
# ---------------------------------------------------------------- heart failure
load("../data-classification/heart_failure.Rda")
X <- heart_failure[, 1:12]
y <- as.character(heart_failure[, 13])

classification_example(X, y, seed = seed_cv_vec[2], kernel_type = kernel_type,
                       path = path, file_name = "0_heart failure")
classification_example_noisy(X, y, seed = seed_cv_vec[2], seed_noisy = seed_label_noise_vec[2], p = 0.25,
                             kernel_type = kernel_type,
                             path = path, file_name = "25_heart failure")
# ------------------------------------------------------------------------ blood
load("../data-classification/blood.Rda")
X <- blood[, 1:4]
y <- as.character(blood[, 5])
2219
classification_example(X, y, seed = seed_cv_vec[3], kernel_type = kernel_type,
                       path = path, file_name = "0_blood")
classification_example_noisy(X, y, seed = seed_cv_vec[3], seed_noisy = seed_label_noise_vec[3], p = 0.25,
                             kernel_type = kernel_type,
                             path = path, file_name = "25_blood")
# --------------------------------------------------------------------- diabetic
load("../data-classification/diabetic.Rda")
X <- diabetic[, 1:19]
y <- as.character(diabetic[, 20])

classification_example(X, y, seed = seed_cv_vec[4], kernel_type = kernel_type,
                       path = path, file_name = "0_diabetic")
classification_example_noisy(X, y, seed = seed_cv_vec[4], seed_noisy = seed_label_noise_vec[4], p = 0.25,
                             kernel_type = kernel_type,
                             path = path, file_name = "25_diabetic")
# -------------------------------------------------------------------- wholesale
load("../data-classification/wholesale.Rda")
X <- wholesale[, 2:8]
y <- as.character(wholesale[, 1])

classification_example(X, y, seed = seed_cv_vec[5], kernel_type = kernel_type,
                       path = path, file_name = "0_wholesale")
classification_example_noisy(X, y, seed = seed_cv_vec[5], seed_noisy = seed_label_noise_vec[5], p = 0.25,
                             kernel_type = kernel_type,
                             path = path, file_name = "25_wholesale")
# -------------------------------------------------------------------- wisconsin
load("../data-classification/wisconsin.Rda")
idx <- which(is.na(wisconsin$BareNuclei) == TRUE)
wisconsin$BareNuclei[idx] <- 0
X <- wisconsin[, 1:9]
y <- as.character(wisconsin[, 10])

classification_example(X, y, seed = seed_cv_vec[6], kernel_type = kernel_type,
                       path = path, file_name = "0_wisconsin")
classification_example_noisy(X, y, seed = seed_cv_vec[6], seed_noisy = seed_label_noise_vec[6], p = 0.25,
                             kernel_type = kernel_type,
                             path = path, file_name = "25_wisconsin")
# ----------------------------------------------------------------- mammographic
load("../data-classification/mammographic.Rda")
for (i in 1:5) {
  idx <- which(is.na(mammographic[,i]))
  mammographic[idx, i] <- 0
}
X <- mammographic[, 1:5]
y <- as.character(mammographic[, 6])

classification_example(X, y, seed = seed_cv_vec[7], kernel_type = kernel_type,
                       path = path, file_name = "0_mammographic")
classification_example_noisy(X, y, seed = seed_cv_vec[7], seed_noisy = seed_label_noise_vec[7], p = 0.25,
                             kernel_type = kernel_type,
                             path = path, file_name = "25_mammographic")
# ---------------------------------------------------------------- UserKnowledge
load("../data-classification/UserKnowledge.Rda")
X <- UserKnowledge[, 1:5]
y <- UserKnowledge$UNS

y[y == "High" | y == "Middle"] <- "Class-1"
y[y == "Very Low" | y == "very_low" | y == "Low"] <- "Class-2"
classification_example(X, y, seed = seed_cv_vec[8], kernel_type = kernel_type,
                       path = path, file_name = "0_user knowledge")
classification_example_noisy(X, y, seed = seed_cv_vec[8], seed_noisy = seed_label_noise_vec[9], p = 0.25,
                             kernel_type = kernel_type,
                             path = path, file_name = "25_user knowledge")
# ------------------------------------------------------------------------- plrx
load("../data-classification/plrx.Rda")
X <- plrx[, 1:12]
y <- as.character(plrx[, 13])

classification_example(X, y, seed = seed_cv_vec[9], kernel_type = kernel_type,
                       path = path, file_name = "0_plrx")
classification_example_noisy(X, y, seed = seed_cv_vec[9], seed_noisy = seed_label_noise_vec[9], p = 0.25,
                             kernel_type = kernel_type,
                             path = path, file_name = "25_plrx")
# ----------------------------------------------------------------- pop_failures
load("../data-classification/pop_failures.Rda")
X <- pop_failures[, 1:20]
y <- as.character(pop_failures[, 21])

classification_example(X, y, seed = seed_cv_vec[10], kernel_type = kernel_type,
                       path = path, file_name = "0_pop failures")
classification_example_noisy(X, y, seed = seed_cv_vec[10], seed_noisy = seed_label_noise_vec[10], p = 0.25,
                             kernel_type = kernel_type,
                             path = path, file_name = "25_pop failures")
# ---------------------------------------------------------------------- titanic
load("../data-classification/titanic.Rda")
X <- titanic[, 1:3]
y <- as.character(titanic[, 4])

classification_example(X, y, seed = seed_cv_vec[11], kernel_type = kernel_type,
                       path = path, file_name = "0_titanic")
classification_example_noisy(X, y, seed = seed_cv_vec[12], seed_noisy = seed_label_noise_vec[12], p = 0.25,
                             kernel_type = kernel_type,
                             path = path, file_name = "25_titanic")
# ---------------------------------------------------------------------- coimbra
load("../data-classification/coimbra.Rda")
X <- as.matrix(coimbra[, 1:9])
y <- as.character(as.matrix(coimbra[, 10]))

classification_example(X, y, seed = seed_cv_vec[12], kernel_type = kernel_type,
                       path = path, file_name = "0_coimbra")
classification_example_noisy(X, y, seed = seed_cv_vec[12], seed_noisy = seed_label_noise_vec[12], p = 0.25,
                             kernel_type = kernel_type,
                             path = path, file_name = "25_coimbra")
# ------------------------------------------------------------------- ionosphere
load("../data-classification/ionosphere.Rda")
X <- as.matrix(ionosphere[, 1:33])
y <- as.character(as.matrix(ionosphere[, 34]))

classification_example(X, y, seed = seed_cv_vec[13], kernel_type = kernel_type,
                       path = path, file_name = "0_ionosphere")
classification_example_noisy(X, y, seed = seed_cv_vec[13], seed_noisy = seed_label_noise_vec[13], p = 0.25,
                             kernel_type = kernel_type,
                             path = path, file_name = "25_ionosphere")
end_time <- Sys.time()
print(end_time - start_time)